Skip to content

grep: allow later options to override earlier ones in option groups - #245

Open
yunusarda-sudo wants to merge 1 commit into
uutils:mainfrom
yunusarda-sudo:grep-cli-options-last-wins
Open

yunusarda-sudo wants to merge 1 commit into
uutils:mainfrom
yunusarda-sudo:grep-cli-options-last-wins

Conversation

@yunusarda-sudo

Copy link
Copy Markdown
Contributor

When conflicting options within the same group were specified on the command line:

  • -a always beat -I, which always beat --binary-files=TYPE;
  • -r / -R always beat -d ACTION;
  • --no-group-separator always beat --group-separator=SEP.

This PR sets up mutual argument overrides for these option groups so that whichever option appears last takes precedence, matching GNU grep behavior.

Fixes #177

@codspeed

codspeed Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Merging this PR will not alter performance

1 warning

⚠️ 3 benchmarks are dominated by system calls

System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.

Learn more about system calls

See affected benchmarks

✅ 10 untouched benchmarks
⏩ 17 skipped benchmarks1


Comparing yunusarda-sudo:grep-cli-options-last-wins (8637414) with main (bf6f25e)

Open in CodSpeed

Footnotes

  1. 17 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

@codecov

codecov Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.23%. Comparing base (bf6f25e) to head (8637414).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #245      +/-   ##
==========================================
+ Coverage   97.22%   97.23%   +0.01%     
==========================================
  Files           6        6              
  Lines        2270     2280      +10     
  Branches      245      246       +1     
==========================================
+ Hits         2207     2217      +10     
  Misses         63       63              
Flag Coverage Δ
macOS_latest 98.14% <100.00%> (+<0.01%) ⬆️
ubuntu_latest 98.14% <100.00%> (+<0.01%) ⬆️
windows_latest 0.00% <0.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@yunusarda-sudo
yunusarda-sudo force-pushed the grep-cli-options-last-wins branch from c4e6e7c to bc618a5 Compare November 25, 2026 16:06
@yunusarda-sudo

Copy link
Copy Markdown
Contributor Author

Cygwin failure is unrelated: color_on_a_terminal_needs_option_and_term_not_dumb is flaky there (same failures on main, https://github.com/uutils/grep/actions/runs/45587825191).

@yunusarda-sudo
yunusarda-sudo force-pushed the grep-cli-options-last-wins branch 2 times, most recently from 8fcd2ee to 6dc6ee5 Compare November 25, 2026 23:05
Configure clap argument overrides for -a / -I / --binary-files, -r / -R / -d, and --group-separator / --no-group-separator so that the later option takes precedence over an earlier one as GNU grep does.

Fixes uutils#177

Signed-off-by: Yunus Arda Güney <yunusarda-sudo@users.noreply.github.com>
@yunusarda-sudo
yunusarda-sudo force-pushed the grep-cli-options-last-wins branch from 6dc6ee5 to 8637414 Compare November 25, 2026 23:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

grep - -a/-I/--binary-files, -r/-d and the group-separator options ignore command-line order

2 participants